﻿using System;
using System.Data;
using System.Collections.Generic;
using BOMS.Model;
namespace BOMS.BLL
{
    /// <summary>
    /// 业务逻辑类S_BatSnapshot 的摘要说明。
    /// </summary>
    public class S_BatSnapshot
    {
        private readonly BOMS.DAL.S_BatSnapshot dal = new BOMS.DAL.S_BatSnapshot();
        public S_BatSnapshot()
        { }
        #region  成员方法
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int ID, int Generation, string EquipID, string BatteryGroup, int BatteryID)
        {
            return dal.Exists(ID, Generation, EquipID, BatteryGroup, BatteryID);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public BOMS.Model.S_BatSnapshot GetModel(int ID, int Generation, string EquipID, string BatteryGroup, int BatteryID)
        {

            return dal.GetModel(ID, Generation, EquipID, BatteryGroup, BatteryID);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<BOMS.Model.S_BatSnapshot> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<BOMS.Model.S_BatSnapshot> DataTableToList(DataTable dt)
        {
            List<BOMS.Model.S_BatSnapshot> modelList = new List<BOMS.Model.S_BatSnapshot>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                BOMS.Model.S_BatSnapshot model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new BOMS.Model.S_BatSnapshot();
                    if (dt.Rows[n]["ID"].ToString() != "")
                    {
                        model.ID = int.Parse(dt.Rows[n]["ID"].ToString());
                    }
                    if (dt.Rows[n]["Generation"].ToString() != "")
                    {
                        model.Generation = int.Parse(dt.Rows[n]["Generation"].ToString());
                    }
                    model.EquipID = dt.Rows[n]["EquipID"].ToString();
                    model.BatteryGroup = dt.Rows[n]["BatteryGroup"].ToString();
                    if (dt.Rows[n]["BatteryID"].ToString() != "")
                    {
                        model.BatteryID = int.Parse(dt.Rows[n]["BatteryID"].ToString());
                    }
                    if (dt.Rows[n]["Vval"].ToString() != "")
                    {
                        model.Vval = decimal.Parse(dt.Rows[n]["Vval"].ToString());
                    }
                    if (dt.Rows[n]["Ival"].ToString() != "")
                    {
                        model.Ival = decimal.Parse(dt.Rows[n]["Ival"].ToString());
                    }
                    if (dt.Rows[n]["Tval"].ToString() != "")
                    {
                        model.Tval = decimal.Parse(dt.Rows[n]["Tval"].ToString());
                    }
                    model.Status = dt.Rows[n]["Status"].ToString();
                    if (dt.Rows[n]["LogTime"].ToString() != "")
                    {
                        model.LogTime = DateTime.Parse(dt.Rows[n]["LogTime"].ToString());
                    }
                    if (dt.Rows[n]["IsNew"].ToString() != "")
                    {
                        if ((dt.Rows[n]["IsNew"].ToString() == "1") || (dt.Rows[n]["IsNew"].ToString().ToLower() == "true"))
                        {
                            model.IsNew = true;
                        }
                        else
                        {
                            model.IsNew = false;
                        }
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  成员方法
    }
}

